home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / e14.zip / ECONFIG.PAS < prev   
Pascal/Delphi Source File  |  1991-12-15  |  9KB  |  337 lines

  1. Program EConfig;
  2. uses CRT, Dos;
  3.  
  4. Const
  5.    ProgramLength = 6337;
  6.    ConfigStarts = $40; {offset from beginning of file}
  7.    {offsets}
  8.    cs = 0;  {Status line attributes  }
  9.    ct = 1;  {text attributes         }
  10.    tw = 2;  {tab width               }
  11.    io = 3;  {insert / overwrite flag }
  12.    ai = 4;  {Autoinsert flag         }
  13.    tm = 5;  {text / program mode flag}
  14.    lm = 6;  {right margin            }
  15.    rm = 7;  {left margin             }
  16.  
  17.    stop = 0;
  18.  
  19. TYPE
  20.   BufArray = array[0..ProgramLength-1] of byte;
  21.  
  22. VAR
  23.    Infile, Outfile : file;
  24.    Buffer : BufArray;
  25.    Cmd : integer;
  26. Function ColorWord(CNum : integer):String;
  27. begin
  28.    case CNum of
  29.    0: ColorWord:='black        ';
  30.    1: ColorWord:='blue         ';
  31.    2: ColorWord:='green        ';
  32.    3: ColorWord:='cyan         ';
  33.    4: ColorWord:='red          ';
  34.    5: ColorWord:='magenta      ';
  35.    6: ColorWord:='brown        ';
  36.    7: ColorWord:='white        ';
  37.    8: ColorWord:='dark grey    ';
  38.    9: ColorWord:='light blue   ';
  39.   10: ColorWord:='light green  ';
  40.   11: ColorWord:='light cyan   ';
  41.   12: ColorWord:='light red    ';
  42.   13: ColorWord:='light magenta';
  43.   14: ColorWord:='yellow       ';
  44.   15: ColorWord:='bright white ';
  45.   end; {case}
  46. end;
  47.  
  48. Procedure PickColor(OffSet : Integer; VAR Buffer : BufArray);
  49. var x,y,cn, fore, back : integer;
  50. begin
  51.    back:=Buffer[ConfigStarts+OffSet] shr 4;
  52.    fore:=Buffer[ConfigStarts+OffSet] and 15;
  53.    textcolor(14);
  54.    textbackground(1);
  55.    for y:=0 to 7 do
  56.       for x:=0 to 15 do
  57.       begin
  58.          Cn:=(y*15)+y+x;
  59.          textcolor(cn and 15);
  60.          textbackground(cn shr 4);
  61.          gotoxy(x*3+33,17+y);
  62.          write(cn:3);
  63.          end;
  64.    gotoxy(1,21);
  65.    textcolor(fore);
  66.    textbackground(back);
  67.    writeln('This is what the current');
  68.    if offset = cs then
  69.       write('status')
  70.    else
  71.       write('text  ');
  72.    writeln(' line looks like. ');
  73.    textcolor(14);
  74.    textbackground(1);
  75.  
  76.    gotoxy(1,20);
  77.    write('                               ');
  78.  
  79.    repeat
  80.       gotoxy(1,19);
  81.       write('New color combination: ');
  82.       read(cn);
  83.       until fore IN [0..127];
  84.    Buffer[ConfigStarts+Offset]:=cn;
  85.    for y:=17 to 25 do
  86.    begin
  87.       gotoxy(1,y);
  88.       clreol;
  89.       end;
  90. end;
  91.  
  92. Procedure SetTab(VAR Buffer : BufArray);
  93. var Tab : byte;
  94. begin
  95.    gotoxy(1,20);
  96.    clreol;
  97.    gotoxy(1,22);
  98.    write('Enter tab width ');
  99.    readln(tab);
  100.    Buffer[ConfigStarts+TW]:=tab;
  101.    gotoxy(1,22);
  102.    clreol;
  103. end;
  104.  
  105. Procedure Beep;
  106. begin
  107.    sound(300);
  108.    delay(400);
  109.    nosound;
  110. end;
  111.  
  112. Procedure SetMargins(VAR Buffer : BufArray);
  113. var left, right : byte;
  114.     tempx,tempy,x: integer;
  115.     c: char;
  116. begin
  117.    gotoxy(1,20);
  118.    clreol;
  119.    gotoxy(1,22);
  120.    write  ('...............................................',
  121.            '.................................');
  122.    left:=Buffer[ConfigStarts+LM]+1;
  123.    right:=Buffer[ConfigStarts+RM]+1;
  124.    gotoxy(left,22);
  125.    write('L');
  126.    gotoxy(right,22);
  127.    write('R');
  128.  
  129.    gotoxy(1,24);
  130.    writeln('   Use: {left} / {right} / {home} / {end}; "L" "R" {return} or {esc}');
  131.    gotoxy(left,22);
  132.    repeat
  133.       tempx:=wherex;
  134.       tempy:=wherey;
  135.       gotoxy(35,25);
  136.       write('Column: ',tempx-1:2);
  137.       gotoxy(tempx,tempy);
  138.       repeat
  139.          c:=upcase(readkey);
  140.       until c in ['L','R',#13,#27,#0];
  141.       case C of
  142.       'L' : if wherex-1 >= Right then
  143.                beep
  144.             else
  145.             begin
  146.                x:=wherex;           {save current cursor pos}
  147.                gotoxy(left,22);
  148.                write('.');          {blank out old margin indicator}
  149.                gotoxy(x,22);
  150.                left:=wherex;
  151.                gotoxy(left,22);
  152.                write('L',#08);      {put new one down and backspace to it}
  153.             end;
  154.       'R' : if wherex-1 <= left then
  155.                beep
  156.             else
  157.             begin
  158.                x:=wherex;
  159.                gotoxy(right,22);
  160.                write('.');
  161.                gotoxy(x,22);
  162.                right:=x;
  163.                gotoxy(x,22);
  164.                write('R',#08);
  165.                if right=80 then
  166.                   gotoxy(80,22);  {Keep TP from wrapping around}
  167.             end;
  168.  
  169.       #0  : begin
  170.                c:=readkey;
  171.                case ord(c) of
  172.                75 : if wherex-1>-1 then   {LEFT ARROW}
  173.                      gotoxy(wherex-1,22);
  174.                77 : if wherex < 80 then   {RIGHT ARROW}
  175.                      gotoxy(wherex+1,22);
  176.                71 : gotoxy(1,22);         {HOME}
  177.                79 : gotoxy(80,22);        {END }
  178.                end;
  179.             end;
  180.       end;
  181.  
  182.    until (C = #13) or (C = #27);
  183.    for x:=20 to 25 do
  184.    begin
  185.       gotoxy(1,x);
  186.       clreol;
  187.       end;
  188.    if c = #27 then exit;
  189.    Buffer[ConfigStarts+LM]:=left-1;
  190.    Buffer[ConfigStarts+RM]:=right-1;
  191.  
  192. end;
  193.  
  194. Procedure OpenFile(VAR Infile:File);
  195. begin
  196.    Assign(infile,'E.COM');
  197.    reset(infile,1);
  198.    BlockRead(infile, buffer, ProgramLength);
  199.    close(infile);
  200. end;
  201.  
  202. Procedure PrintHeading;
  203. begin
  204.    textcolor(14);
  205.    textbackground(1);
  206.    clrscr;
  207.    gotoxy(1,3);
  208.    writeln('                         E   C O N F I G U R A T I O N');
  209.    writeln;
  210.    writeln('     E.COM               (C) Copyright 1990, David Nye, MD.');
  211.    writeln('     ECONFIG.EXE         (C) Copyright 1990, Jim DeVries');
  212.    writeln;
  213.    write  ('───────────────────────────────────────────────',
  214.            '─────────────────────────────────');
  215.    gotoxy(1,9);
  216.    writeln('                                              Currently:');
  217.    writeln('     1.  Status line colors.................');
  218.    writeln('     2.  Text colors........................');
  219.    writeln('     3.  Tab width..........................');
  220.    writeln('     4.  Toggle Insert / Overwrite mode.....');
  221.    writeln('     5.  Toggle AutoInsert..................');
  222.    writeln('     6.  Toggle Program / Text mode.........');
  223.    writeln('     7.  Change Margins for text mode.......');
  224. end;
  225.  
  226. Procedure ShowCurrent(VAR Buffer : BufArray);
  227. var r,l, temp, back, fore : byte;
  228. begin
  229.    back:=Buffer[ConfigStarts+CS] shr 4;
  230.    fore:=Buffer[ConfigStarts+Cs] and 15;
  231.    gotoxy(47,10);
  232.    write(ColorWord(fore),' ON ', ColorWord(back));
  233.    clreol;
  234.    back:=Buffer[ConfigStarts+CT] shr 4;
  235.    fore:=Buffer[ConfigStarts+CT] and 15;
  236.    gotoxy(47,11);
  237.    write(ColorWord(fore),' ON ', ColorWord(back));
  238.    clreol;
  239.    temp:=Buffer[ConfigStarts+TW];
  240.    gotoxy(47,12);
  241.    write(Temp);
  242.    temp:=Buffer[ConfigStarts+IO];
  243.    gotoxy(47,13);
  244.    if temp=$FF then Write('INSERT   ')
  245.       else write('OVERWRITE');
  246.    gotoxy(47,14);
  247.    temp:=Buffer[ConfigStarts+AI];
  248.    If temp=$FF then write('ON ')
  249.       else write('OFF');
  250.    gotoxy(47,15);
  251.    temp:=Buffer[ConfigStarts+TM];
  252.    If temp=$FF then write('TEXT MODE   ')
  253.       else write('PROGRAM MODE');
  254.    l:=Buffer[ConfigStarts+LM];
  255.    r:=Buffer[ConfigStarts+RM];
  256.    gotoxy(47,16);
  257.    write(l, ' L & ',r,' R');
  258.    gotoxy(1,20);
  259.    write('     Change (1..7)  Esc to quit');
  260.  
  261. end;
  262.  
  263. Procedure GetCommand(VAR Cmd : integer);
  264. var c: char;
  265. begin
  266.    repeat
  267.       c:=readkey;
  268.    until C in ['1'..'7',#27];
  269.    If C=#27 then Cmd:=Stop
  270.       else Cmd:=Ord(C)-Ord('0');
  271. end;
  272.  
  273. procedure ProcessCmd(Cmd : Integer; VAR Buffer : BufArray);
  274. begin
  275.    Case Cmd of
  276.    Stop : Exit;
  277.    1: PickColor(CS, Buffer);
  278.    2: PickColor(CT, Buffer);
  279.    3: SetTab(Buffer);
  280.    4: Buffer[ConfigStarts+IO]:= Buffer[ConfigStarts+IO] XOR $FF;
  281.    5: Buffer[ConfigStarts+AI]:= Buffer[ConfigStarts+AI] XOR $FF;
  282.    6: Buffer[ConfigStarts+TM]:= Buffer[ConfigStarts+TM] XOR $FF;
  283.    7: SetMargins(Buffer);
  284.    end;
  285.  
  286. end;
  287.  
  288. Procedure CloseFile(VAR Buffer : BufArray);
  289. var yn : char;
  290.     fn : string;
  291.     outfile : file;
  292. begin
  293.    gotoxy(1,20);
  294.    clreol;
  295.    write('     Save changes? [Y/N] ');
  296.    repeat
  297.       yn:=readkey;
  298.    until upcase(yn) IN ['Y','N'];
  299.    writeln;
  300.    if upcase(yn) = 'N'
  301.       then exit
  302.    else
  303.    begin
  304.       write('    Save to E.COM? [Y/N] ');
  305.       Repeat
  306.          yn:=readkey;
  307.       until upcase(yn) in ['Y','N'];
  308.       if upcase(YN) = 'N' then
  309.       begin
  310.          writeln;
  311.          write('     Enter new file name: ');
  312.          read(fn);
  313.          end
  314.       else
  315.          fn:='E.COM';
  316.       end;
  317.    assign(outfile,fn);
  318.    if fn = 'E.COM' then
  319.       reset(outfile, 1)
  320.    else
  321.       rewrite(outfile);
  322.  
  323.    blockwrite(outfile, Buffer, ProgramLength);
  324.  
  325.    close(outfile);
  326. end;
  327.  
  328. begin
  329.    OpenFile(Infile);
  330.    PrintHeading;
  331.    repeat
  332.       ShowCurrent(buffer);
  333.       GetCommand(Cmd);
  334.       ProcessCmd(Cmd,Buffer);
  335.       until Cmd = Stop;
  336.    closefile(buffer);
  337. end.